﻿SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
ALTER TABLE dbo.bht_Columns ADD
	RegexValidation nvarchar(100) NULL,
	Description nvarchar(400) NULL,
	HideForEdition bit NOT NULL CONSTRAINT DF_bht_Columns_HideForEdition DEFAULT 0
GO


ALTER PROCEDURE [dbo].[bhp_NemoGroupColumnsGet]
	@GroupId				INT
AS
BEGIN
	
	
	SELECT 
		id as ColumnId,
		name as ColumnName,
		ct.EnumType as ColumnType,
		r.rel as RelatedGroupId,
		ISNULL(c.DisplayName, name) as DisplayName,
		ISNULL(c.FormattingValue, '{0}') as FormattingValue,
		r.sort as ColumnSort,
		c.RegexValidation,
		c.[Description],
		ISNULL(c.HideForEdition, 0) as HideForEdition
	FROM
		sTree t
		INNER JOIN sRel r ON t.id = r.field AND t.parent = r.tab
		INNER JOIN bht_ColumnTypes ct ON t.typ = ct.ColumnType
		LEFT JOIN bht_Columns c ON t.id = c.ColumnId
	WHERE
		parent = @GroupId
		AND t.del = 0
		AND r.del = 0
		AND ((t.typ NOT IN ('F', 'I', 'D', 'DT') AND r.rel > 0) OR (t.typ IN ('F', 'I', 'D', 'DT')))

END
